<?php
/**
 * mock_fmw_api
 * FmwBosestoreController.php
 * @author: Heze
 * Date: 2023/8/16 13:38
 */

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class FmwBosestoreController extends Controller
{
    public function index(Request $request)
    {
        $method = $request->get('act');
        if (empty($method)) {
            return [];
        }
        $method = str_replace('.', '_', $method);

        if (!method_exists($this, $method)) {
            echo sprintf("[%s] mock function not exists", $method);
            exit;
        }

        return $this->$method($request);
    }

    public function LogisticsOfflineSendRequest()
    {
//        return response('error data', 400);

        return [
            'logistics_offline_send_response' => [
                'shipping' => [
                    'is_success' => false,
                ],
            ],
        ];
    }

    public function TradesSoldIncrementGetRequest()
    {
        $res = [
            "trades_sold_increment_get_response" => [
                "trades" => [
                    [
                        "post_fee" => 0.01,
                        "buyer_message" => "test",
                        "created" => "2023-11-14 09:36:10",
                        "receiver_city" => "北京市",
                        "receiver_district" => "昌平区",
                        "shipping_type" => "express",
                        "receiver_mobile" => "15651111251",
                        "discount_fee" => 0,
                        "invoice_name" => "",
                        "tid" => "SY2023111410001",
                        "pay_time" => "2023-11-14 09:36:16",
                        "receiver_state" => "北京市",
                        "buyer_nick" => "沈阳",
                        "order_status" => "WAIT_SELLER_SEND_GOODS",
                        //"order_status" => "TRADE_FINISHED",
                        "invoice_kind" => 1,
                        "receiver_zip" => "102209",
                        "receiver_address" => "创意产业园12栋",
                        "receiver_name" => "李四",
                        "orders" => [
                            [
                                "outer_iid" => "SKUA00002",
                                "num" => 1,
                                "total_fee" => 0.01,
                                "num_iid" => "SYSKUA00002",
                                "title" => "测试商品-绿色",
                            ],
                        ],
                        "payer_register_no" => "",
                        "payment" => 0.02,
                        "alipay_no" => "SY202311141000101",
                        "order_type" => 1,
                        "openid" => "zh777",
                        "unionid" => "zhzhzh",
                        "sign_time" => "",
                        //"sign_time" => "2023-11-14 15:36:16",
                        "order_fq_num" => 3,
                        "order_is_free" => 1,
                    ],
                ],
                "total_results" => 1,
            ],
        ];

        return $res;
    }

    public function ProductsIncrementGetRequest()
    {
        $sku = [
            "sku_name" => 'BoseStoreMock 商品 SKUA001',
            "sku_code" => 'BoseStoreMockSKUA001',
            "price" => 111,
        ];

        $product = [
            'status' => 2,
            'spu_name' => 'BoseStoreMock 商品 SPUA001',
            'spu_code' => 'BoseStoreMockSPUA001',
            'category_code' => '1111',
            'skus' => [
                $sku
            ],
        ];

        return [
            "products_increment_get_response" => [
                "total_results" => "1",
                "products" => [
                    $product
                ]
            ]
        ];
    }
}
